package project;

import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class EmailTester {

	public EmailTester() throws MessagingException {

		String host = "smtp.gmail.com";
		String Password = "";//			ei tuka te trqbava da si slojite pass na maila 
		String from = "stoiko.m.stoikov@gmail.com";//		tuka trqbva da si slojite va6iq mail ZADULJITELNO GMAIL ACC
		String toAddress = "nikolay.tomitov@softacad.bg";
		String filename = "E:/Java_Android/WorkPlace/SVN_Project/src/project/serialize.ser";// tuka trqbva da si napi6ete va6ta puteka do faila
		
		// Get system properties
		Properties props = System.getProperties();
		props.put("mail.smtp.host", host);
		props.put("mail.smtps.auth", "true");
		props.put("mail.smtp.starttls.enable", "true");
		Session session = Session.getInstance(props, null);

		MimeMessage message = new MimeMessage(session);

		message.setFrom(new InternetAddress(from));

		message.setRecipients(Message.RecipientType.TO, toAddress);

		message.setSubject("JavaMail Attachment");

		BodyPart messageBodyPart = new MimeBodyPart();

		messageBodyPart.setText("Mnogo se se izku6avam da go sloja v 1 cikul da te naspamq :D");

		Multipart multipart = new MimeMultipart();

		multipart.addBodyPart(messageBodyPart);

		messageBodyPart = new MimeBodyPart();

		DataSource source = new FileDataSource(filename);

		messageBodyPart.setDataHandler(new DataHandler(source));

		messageBodyPart.setFileName(filename);

		multipart.addBodyPart(messageBodyPart);

		message.setContent(multipart);

		try {
			Transport tr = session.getTransport("smtps");
			tr.connect(host, from, Password);
			tr.sendMessage(message, message.getAllRecipients());
			System.out.println("\n\nMail Sent Successfully");
			tr.close();

		} catch (SendFailedException sfe) {

			System.out.println(sfe);
		}
	}
}
